﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NRCP.BusinessEntities;

namespace NRCP.BusinessLogicLayer
{
    public partial class NationalPlanDetailsMonthlyBLL
    {
        internal List<NationalPlanDetailsMonthly> GetNationalPlanDetailsMonthliesByNationalPlanId(int nationalPlanId)
        {
            List<NationalPlanDetailsMonthly> result = (from monthlies in _socialShareDatabaseContext.NationalPlanDetailsMonthlies
                          join yearlies in _socialShareDatabaseContext.NationalPlanDetailsYearlies
                          on monthlies.NationalPlanDetailsYearlyId equals yearlies.Id
                          where yearlies.NationalPlanId == nationalPlanId
                          select monthlies).ToList();
            return result;
        }

        internal List<NationalPlanDetailsMonthly> GetMonthlyPlans(int nationalPlanId,int divisionId,int fishId)
        {
            try
            {
                List<NationalPlanDetailsMonthly> result = null;
                NationalPlanDivision planDivision=new NationalPlanDivisionBLL().GetNationalPlanDivision(obj => obj.DivisionId == divisionId && obj.NationalPlanId == nationalPlanId);
                NationalPlanFish planFish = new NationalPlanFishBLL().GetNationalPlanFish(obj => obj.FishId == fishId && obj.NationalPlanId == nationalPlanId);
                if (planDivision != null && planFish != null)
                {
                    result = (from monthlies in _socialShareDatabaseContext.NationalPlanDetailsMonthlies
                              join yearlies in _socialShareDatabaseContext.NationalPlanDetailsYearlies
                              on monthlies.NationalPlanDetailsYearlyId equals yearlies.Id
                              where yearlies.NationalPlanId == nationalPlanId
                              && yearlies.FishId == fishId
                              && yearlies.DivisionId == divisionId
                              select monthlies).ToList();
                }
                return result;
            }
            //handling other exceptions...
            catch (Exception ex)
            {
                //Error handling
                throw ex;
            }
        }
    }
}